package tum0r.cryptology.encryption;

import tum0r.misc.StringUtils;

/**
 * 工程: JavaTools<br>
 * 包: tum0r.cryptology.encryption<br>
 * 创建者: tum0r<br>
 * 创建时间: 2020/8/22 20:20<br>
 * <br>
 */
public class AffineEncryption {
    public String encryption(String plainText, int m, int n) {
        StringBuilder cipherText = new StringBuilder();
        if (!StringUtils.isNullOrEmptyOrSpace(plainText)) {
            char[] temp = plainText.toCharArray();
            for (char c : temp) {
                if ((c >= 65 && c <= 90)) {
                    cipherText.append((char) (((c - 'A') * m + n) % 26 + 'A'));
                } else if ((c >= 97 && c <= 122)) {
                    cipherText.append((char) (((c - 'a') * m + n) % 26 + 'a'));
                }
            }
        }
        return cipherText.toString();
    }
}
